<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0" />
    <title>沃闪购</title>
    <link rel="stylesheet" href="../css/normalize.css" />
    <link rel="icon" href="../img/bitbug_favicon.ico" type="image/x-icon" />
    <!--<link rel="stylesheet" href="index.css"/>-->
    <!--<link rel="stylesheet" href="../index.css"/>-->
    <link rel="stylesheet" href="../index_format.css" />
    <link rel="stylesheet" href="../css/layer.css" />

    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/rem.js"></script>
    <script type="text/javascript" src="../js/tool.js"></script>


</head>

<body onload="preventMove()">
    <div class="header">
        <div><img src="../img/wo-logo.png" alt="" /></div>
        <div class="wo-topic">沃闪购合作营销平台</div>
    </div>
    <div class="container">
        <div class="flex-box">
            <div class="choose-info">
                <div class="user-info">
                    <p><img id="user_img" alt="" /></p>
                    <p><span id="user_id" </p>
                        <!-- <p><span id="user_id"></span><a href="login.html">退出</a></p>
                    <p><span>审核状态：</span><i id="user_state" class=""></i></p>
                    <p><span>归属店：</span><i id="user_channel"></i></p> -->
                    <!-- <a id="refresh" href="#" class="refresh"></a> -->
                </div>

                <div class="code-link">
                    <p class="code-info">请扫码订购产品</p>
                    <p class="code-img"><b id="grcode"></b></p>
                </div>
                <p class="btn-group">
                    <a href="poster.html" class="btn-style">返回</a>
                </p>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="../js/layer.js"></script>

    <script type="text/javascript" src="../js/qrcode.min.js"></script>

    <script>
        var bes_code = {
            user_info: '.user-info',
            user_img: "#user_img",
            user_id: '#user_id',
            user_state: '#user_state',
            user_channel: '#user_channel',
            refresh: "#refresh",
            host_server: getServerHost(),
            info_url: '/api/shopping/userInfo?',
            my_code: '/api/shopping/QRCode?',
            init: function() {
                this.getInfo();
                this.refreshBtn();
                this.getCode();
            },
            userInfo: function(id, name, status) {
                var context = this;
                console.log(id, name, status)
                if (id) {
                    $(context.user_img).attr('src', "../img/user.png");
                    $(context.user_id).html(id);
                    $(context.user_id).attr("data-id", id);
                    if ('1' == status) {
                        $(context.user_state).attr('class', 'red-info').html('未审核');

                    } else if ('2' == status) {
                        $(context.user_state).attr('class', 'green-info').html('已通过');

                    } else if ('3' == status) {
                        $(context.user_state).attr('class', 'red-info').html('已冻结');

                    } else {
                        console.log(status)
                    }
                    $(context.user_channel).html(name);
                } else {
                    console.log('no get info')
                }
            },
            getInfo: function() {
                var context = this;
                var data = JSON.parse(sessionStorage.getItem('res'));

                setTimeout(function() {
                    $.ajax({
                        type: 'GET',
                        url: context.host_server + context.info_url,
                        data: "userId=" + data.userId,
                        success: function(response) {
                            var res = response.res;
                            if ('200' == response.code) {
                                context.userInfo(res.account_no, res.channel_name, res.status);
                                sessionStorage.setItem('accountNo', res.account_no);
                            } else {
                                alert('获取用户信息失败')
                            }

                            //                            context.showNeeds(context.count, response);
                        },
                        error: function() {
                            alert(' 返回数据出现异常');
                        }
                    });
                    //                获取用户信息

                }, 1000)


            },
            getCode: function() {
                var context = this;
                var data = JSON.parse(sessionStorage.getItem('res'));
                setTimeout(function() {
                    $.ajax({
                        type: 'GET',
                        url: context.host_server + context.my_code,
                        data: "userId=" + data.userId,
                        success: function(response) {
                            //                        var res = response.res;
                            var qrcode = new QRCode(document.getElementById("grcode"), {
                                width: 140,
                                height: 140,
                                text: response.res
                            });
                        },
                        error: function() {
                            alert(' 返回数据出现异常');
                        }
                    });
                    //                获取用户信息

                }, 1000)
            },
            refreshBtn: function() {
                var context = this;
                $('#refresh').click(function(e) {
                    e.preventDefault();
                    $(this).addClass('active');
                    var self = this;
                    var timer = setTimeout(function() {
                        $(self).removeClass('active');
                        window.location.reload();
                        timer = null;
                        clearTimeout(timer);
                    }, 2000);
                    //                context.userInfo();
                })
            },
        }
        bes_code.init();
    </script>
</body>

</html>
